/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dpy.appmvdpy.Controllers;

import com.dpy.appmvdpy.Facades.DefaultFacade;
import com.dpy.appmvdpy.Facades.ProdutosFacade;
import com.dpy.appmvdpy.Models.Clientes;
import com.dpy.appmvdpy.Models.Exporters.PedidoExporter;
import com.dpy.appmvdpy.Models.FormaPagamento;
import com.dpy.appmvdpy.Models.Importers.Importer;
import com.dpy.appmvdpy.Models.Importers.ProdutoImporter;
import com.dpy.appmvdpy.Models.Produtos;
import com.dpy.appmvdpy.Models.Validators.DefaultValidator;
import com.dpy.appmvdpy.Models.Validators.ProdutosValidator;
import com.dpy.appmvdpy.Models.Vendedor;
import java.beans.PropertyEditorSupport;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author ac_psoares
 */
@Controller
@RequestMapping("/produtos")
public class ProdutosController extends DefaultController<Produtos> {
    
    public ProdutosController()
    {
       super(Produtos.class,"produtos");    
    }    
    
    
    @Autowired
    public ProdutoImporter importer;
     
    @Autowired
    private ProdutosFacade facade;
    
    @Autowired
    private ProdutosValidator validator;    
    
    @Override
    public DefaultFacade<Produtos> getFacade() {
       return this.facade;
    }

    @Override
    public Produtos createObject() {
        return new Produtos();
    }

    @Override
    public DefaultValidator<Produtos> getValidator() {
        return this.validator;
    }
    
    
    @Override
    @Secured("ROLE_ADMIN")
    public ModelAndView search(String name) {
        return super.search(name);
    }

    @Override
    @Secured("ROLE_ADMIN")
    public ModelAndView edit(int id) {
        return super.edit(id);
    }

    @Override
    @Secured("ROLE_ADMIN")
    public ModelAndView list(@RequestParam(required=false,defaultValue="0")int pag) {
        return super.list(pag);
    }

    @Override
    @Secured("ROLE_ADMIN")
    public ModelAndView create() {
        return super.create();
    }

    @Override
    @Secured("ROLE_ADMIN")
    public ModelAndView create(Produtos model, BindingResult result, SessionStatus status) {
        return super.create(model, result, status);
    }

    @Override
    @Secured("ROLE_ADMIN")
    public ModelAndView Import() {
        return super.Import();
    }  
    
    
    @Override
    public Importer<Produtos> getImporter(File file) {
        importer.setFile(file);
        return importer;
    }
    
}
